<template>
	
	<view>
		<view class="goods_list"
			<goods-list @goodsItemClick="goGoodsDetail":goods="goods"></goods-list>
			<view class="isover" v-if="flag"> ---我是有底线的--- </view>
		</view>
	</view>
	
</template>

<script>
import goodsList from '../../components/goods_list.vue'
export default {
	data() {
		return {
			pageindex: 1,
			goods:[],
			flag:false
		};
	},
	components: { "goods-list": goodsList },
	onLoad() {
		this.getGoodsList();
	},
	methods: {
		// 获取商品列表
		async getGoodsList() {
			const res = await this.$myRuquest({
				url: '/api/getgoods?pageindex=' + this.pageindex
			});
			// 吧所有的数据放在一个集合
			this.goods= [...this.goods,...res.data.message ]
			
		},
		// 导航到商品详细页
		goGoodsDetail(id){
			console.log("点击了")
			uni.navigateTo({
				url:'/pages/goods-detail/goods-detail?id='+id
			})
		}
		
	},
	onReachBottom() {
		// 下拉加载更多 ...数据结束
		if(this.goods.length<(this.pageindex*10))
		return this.flag =true
		console.log('on bottom。。。')
		this.pageindex++
		this.getGoodsList()
	},
	onPullDownRefresh() {
		this.pageindex=1 
	}
};
</script>

<style lang="scss">
	.goods_list{
		background: #eee;
	}
	.isover{
		width: 100%;
		height: 50px;
		text-align: center;
		background: #eee;
		font-size: 28rpx;
	}
</style>
